<?php
    $item_menu[0] = 1;
    $item_menu[1] = 8; 
    $title = 'Corregir URL';

	include('header.php');

	if (!isset($_SESSION["admin"])) {redirect("login.php");	exit(); }

    $titulo         = 'Correccion de URL';    


	$submit = request('submit','');
    if (!empty($submit)) {
        $anterior = request('anterior','');
        $nueva = request('nueva','');
        
        if (!empty($anterior) and !empty($nueva)) {
            //----- Categorias
            $rs = $db->execute("select * from categorias");
            $x = $rs->GetRows();
            foreach($x as $z) {
                $id = $z['id'];
                $cuerpo1   = str_replace($anterior,$nueva,$z['cuerpo1']);
                $sql = "update categorias set cuerpo1='$cuerpo1' where id='$id'";
                $rs = $db->execute($sql);
            }            

            //----- Publicaciones
            $rs = $db->execute("select * from publicaciones");
            $x = $rs->GetRows();
            foreach($x as $z) {
                // $id = $z['id'];
                $z['copete1'] = str_replace($anterior,$nueva,$z['copete1']);
                $z['contenido1'] = str_replace($anterior,$nueva,$z['contenido1']);

                $ok = $db->Replace('publicaciones', $z,'id', $autoquote = true); 
            }            


            //----- Modulos
            $rs = $db->execute("select * from modulos");
            $x = $rs->GetRows();
            foreach($x as $z) {
                $id = $z['id'];
                $descripcion = str_replace($anterior,$nueva,$z['descripcion']);
                $script      = str_replace($anterior,$nueva,$z['script']);
                $sql = "update modulos set descripcion='$descripcion', script='$script' where id='$id'";
                $rs = $db->execute($sql);
            }            
             



            //----- Slides
            $rs = $db->execute("select * from slides");
            $x = $rs->GetRows();
            foreach($x as $z) {

                if (!empty($z['data'])) {

                    $xdata = unserialize($z['data']);
                  
                    $clave = 0;
                    foreach($xdata as $value) {
                        $data[$clave]['imagen'] = str_replace($anterior,$nueva,$value['imagen']); 
                        $data[$clave]['posicion_texto'] = $value['posicion_texto'];
                        $data[$clave]['texto'] = html_entity_decode($value['texto']);
                        $data[$clave]['href'] = $value['href'];
                        $clave++;
                        
                    }
                    $xdata = serialize($data);
    
                    $id = $z['id'];
                    $sql = "update slides set data='$xdata' where id='$id'";
                    $rs = $db->execute($sql);

                    
                }
            }            








            
            $_SESSION['Msg']='Cambios realizados correctamente.';
        }    
	}


	if(!empty($_SESSION['Msg'])) {
	   echo mensaje_ok($_SESSION['Msg']);
		$_SESSION['Msg']='';
	}
?>

<h2>Reemplazo de URL en imagenes</h2>
<center>
<form action='corregir_url.php' method='post'>
<table width='400'>
    <tr>
        <td width="200" class="th">URL Anterior</td>
        <td width='200'><input type='text' name='anterior' value='' size='50'/></td>
    </tr>
    <tr>
        <td width="200" class="th">URL Nueva</td>
        <td width='200'><input type='text' name='nueva' value='<?=URL;?>' size='50'/></td>
    </tr>
	<tr>
		<td colspan="4" align="center"><br />
		<input type="submit" name="submit" value="Comenzar" />
		</td>
	</tr>
</table>
</form>
</center>
		</td>
    </tr>
</table>
</div>
</body></html>